<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddUserIdToTagsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('tags', function (Blueprint $table) {
            $table->integer('user_id')->nullable();
        });

        $adminUser = \WoXuanWang\User\Models\User::where("name", "admin")->first();
        if ($adminUser) {
            \DB::table('tags')->update(['user_id' => $adminUser->id]);
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('tags', function (Blueprint $table) {
            $table->dropColumn('user_id');
        });
    }
}
